package com.lyc.yuki.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;

/**
 * @Author: lyc
 * @Date: 2025/7/24 22:53
 */
public class CustomTimestampSerializer extends JsonSerializer<Timestamp> {

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public void serialize(Timestamp timestamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String formatDateTime = timestamp.toLocalDateTime().format(formatter);
        jsonGenerator.writeString(formatDateTime);
    }
}
